#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace NativeTest_Question3
{
	void Swap(char& a, char&  b)
	{
		a = a^b;
		b=  a^b;
		a = a^b;
	}

	int RemoveDepulicate(char* str)
	{
		int result = -1;
		int flag = 0;

		char* end=str;
		while(*end)
		{
			++end;
		}
		--end;
		
		while(str <= end)
		{
			if(flag & 1<<(*str-96))
			{
				Swap(*str, *end);
				--end;
			}
			else
			{
				flag |= 1<<(*str-96);
				++str;
				++result;
			}
		}

		return result;
	}
}

namespace NativeTest
{
	using namespace NativeTest_Question3;

	TEST_CLASS(Question3)
	{
	public:
		
		TEST_METHOD(Question3_TestMethod1)
		{
			// TODO: Your test code her
			char str[]= "abcdef";
			int result = RemoveDepulicate(str);
			Assert::AreEqual(5, result);
		} 

		TEST_METHOD(Question3_TestMethod2)
		{
			char str[]= "abcdddddef";
			int result = RemoveDepulicate(str);
			Assert::AreEqual(5, result);
		} 


		TEST_METHOD(Question3_TestMethod3)
		{
			char str[]= "aaabcdddddef";
			int result = RemoveDepulicate(str);
			Assert::AreEqual(5, result);
		} 

		TEST_METHOD(Question3_TestMethod4)
		{
			char str[]= "abcdddddeffff";
			int result = RemoveDepulicate(str);
			Assert::AreEqual(5, result);
		} 

		TEST_METHOD(Question3_TestMethod5)
		{
			char str[]= "";
			int result = RemoveDepulicate(str);
			Assert::AreEqual(-1, result);
		} 
	};
}